import 'package:flutter/material.dart';
import 'package:flutter_douban/config/app_colors.dart';
import 'package:flutter_douban/main_page/class/model/class_list_model.dart';
import 'package:flutter_douban/main_page/class/page/classroom_detail_page.dart';
import 'package:flutter_douban/main_page/class/page/classroom_more_page.dart';
import 'package:flutter_douban/tool_views/cached_network_Image.dart';

import 'class_item_view.dart';

class ClassHeaderView extends StatefulWidget {
  final ClassListModel model;
  const ClassHeaderView({Key? key,required this.model}) : super(key: key);

  @override
  _ClassHeaderViewState createState() => _ClassHeaderViewState();
}

class _ClassHeaderViewState extends State<ClassHeaderView> {

  @override
  Widget build(BuildContext context) {
    return Container(
      color: AppColors.page,
      width: MediaQuery.of(context).size.width,
      height: 350,
      margin: EdgeInsets.only(top: 15, bottom: 0, left: 0, right: 0),
      child: Column(
        children: [
          _titleWidget(),
          Container(
            width: MediaQuery.of(context).size.width,
            height: 300,
            child: ListView.builder(
                shrinkWrap: true,
                scrollDirection: Axis.horizontal,
                ///禁用滑动事件
                physics: AlwaysScrollableScrollPhysics(),
                itemCount: widget.model.courses!.length,
                itemBuilder: (BuildContext context, int index) {
                  return ClassItemView(list: widget.model.courses!,isHorizontal: true,index: index,);
                }),
          )
        ],
      ),
    );
  }

  Widget _titleWidget() {
    return Container(
      margin: EdgeInsets.only(left: 20,right: 20),
      height: 50,
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          Text(widget.model.title!,
              style: TextStyle(
                  fontSize: 20,
                  color: Colors.black,
                  fontWeight: FontWeight.bold)),
          InkWell(
            child: Text('更多',
                textAlign: TextAlign.center,
                style: TextStyle(
                    fontSize: 13,
                    color: Color.fromRGBO(94, 146, 140, 1),
                    fontWeight: FontWeight.w400)),
            onTap: () {
              Navigator.of(context).push(MaterialPageRoute(builder: (_) {
                return ClassRoomMorePage(titleStr: widget.model.title!,);
              }));
            },
          ),
        ],
      ),
    );
  }

}

